#!/bin/bash
REPO_URL="registry.cn-beijing.aliyuncs.com/shuozhu1234/"
ACTION_URL="http://flow-openapi.aliyun.com/pipeline/webhook/fMcv0C4WqKLXHI1K9hfD"
if [[ ${1} == "" ]];then
  echo "usage: ${0} nginx:latest"
  exit
fi
curl --header "Content-Type: application/json" --request POST --data "{\"IMAGE_NAME\":\"${1}\"}" ${ACTION_URL}
echo
while true
do
  echo "镜像拉取中,请稍候......"
  sleep 1
  docker pull ${REPO_URL}${1##*/} 2>/dev/null
  if [[ $? == "0" ]];then
    break
  fi
done 

docker tag ${REPO_URL}${1##*/} ${1}
docker image rm ${REPO_URL}${1##*/}
